<?php
declare (strict_types = 1);

namespace app\common\listener\websocket;

use adminmatrix\swoole\WebSocket;
use think\facade\Log;

class Open
{
    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($server, $request)
    {
        $fd = $request->fd;
        Log::info("WebSocket 客户端连接成功，fd: {$fd}");
        
        // 发送欢迎消息
        WebSocket::push($fd, json_encode([
            'type' => 'welcome',
            'message' => '连接成功',
            'fd' => $fd
        ]));
    }
}
